package com.sctvcloud.dongqu.ui.adapter.holder;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.ruihang.generalibrary.ui.adapter.holder.BaseRecylerHolder;
import com.ruihang.generalibrary.ui.widget.CustomEXImageView;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.DateUtils;
import com.sctvcloud.dongqu.R;
import com.sctvcloud.dongqu.beans.FHistory;
import com.sctvcloud.dongqu.ui.utils.GlideUtil;
import com.sctvcloud.dongqu.ui.utils.UIUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/6/23 0023.
 */

public class HistoriesHolder extends BaseRecylerHolder<FHistory> implements View.OnClickListener {
    @BindView(R.id.item_histories_title)
    protected CustomFontTextView title;
    @BindView(R.id.item_histories_time)
    protected CustomFontTextView time;
    @BindView(R.id.item_histories_type)
    protected CustomFontTextView type;
    @BindView(R.id.item_histories_img)
    protected CustomEXImageView img;
    @BindView(R.id.item_histories_ll_time_title)
    public LinearLayout llTimeTitle;
    @BindView(R.id.item_histories_time_title)
    public CustomFontTextView tvTimeTitle;
    @BindView(R.id.item_news_type)
    protected ImageView news_type;
    @BindView(R.id.item_histories_img_layout)
    protected RelativeLayout item_histories_img_layout;
    @BindView(R.id.newes_detail_click_count)
    protected CustomFontTextView clickcount;

    private FHistory history;

    public HistoriesHolder(Context context, View itemView) {
        super(context, itemView);
        itemView.setOnClickListener(this);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(FHistory history) {
        this.history = history;
        title.setText(history.getNewsTitle());
        time.setText(DateUtils.formatDate(DateUtils.getDataDate(history), ""));
        clickcount.setText(UIUtils.getReadingNumber(history.getViews()));
        if (!TextUtils.isEmpty(history.getNewsImage())) {
            GlideUtil.getGlideWithSmall169Def(context, history.getNewsImage()).into(img);
            item_histories_img_layout.setVisibility(View.VISIBLE);
            title.setLines(3);
        } else {
            img.setImageResource(R.mipmap.icon_def_16_9_s);
            item_histories_img_layout.setVisibility(View.GONE);
            title.setMaxLines(2);
        }
        type.setText(history.getLable());
        type.setVisibility(View.GONE);
        if (history.isLiving()) {
            news_type.setImageResource(R.mipmap.icon_home_play);
            news_type.setVisibility(View.VISIBLE);
        } else if (history.getNewsType() == 2) { //音频
            news_type.setImageResource(R.mipmap.icon_home_voice);
            news_type.setVisibility(View.VISIBLE);
        } else if (history.getNewsType() == 3) {   //视频
            news_type.setImageResource(R.mipmap.icon_home_play);
            news_type.setVisibility(View.VISIBLE);
        } else {
            news_type.setVisibility(View.GONE);
        }
    }

    @Override
    public void onClick(View v) {
        if (internalClick != null) {
            itemView.setTag(R.id.adapter_item_data_key, history);
            internalClick.onItemInternalClick(itemView, v, getAdapterPosition());
        }
    }
}
